<?php
/**
 * Created by PhpStorm.
 * User: function
 * Date: 2018-04-11
 * Time: 23:19
 */

namespace app\common\logic;

use app\common\logic\Logic;
use app\common\model\Goods;
use app\common\model\Group;
use app\common\model\GroupData;
class GroupLogic extends Logic
{
    protected $modelClass = 'app\common\model\Group';
    protected $column = 'user_id,id,status,validate';
    //除了新增group之外，还要有groupdata
    public function add($params){
    
        $group = new Group();
        $group->allowField(true)->save($params);

        $dataArr = [];
        foreach ($params['mall'] as $key => $mall){

            $dataArr[] = ['group_id'=>$group->id,'mall_id'=>$key,'price'=>$mall['price'],'stock'=>$mall['stock']];
        }
        
        $data = new GroupData();
    
        $data->allowField(true)->saveAll($dataArr);
    
        return $group->id;
        
    }
    

    
    
}